package miiteen.sys.config;

import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.filter.DelegatingFilterProxy;

import java.util.ArrayList;
import java.util.List;

@Configuration
public class FilterConfiguration {

    @Bean
    public FilterRegistrationBean delegatingFilterProxy() {
        //创建 过滤器注册bean
        FilterRegistrationBean registrationBean = new FilterRegistrationBean();
        DelegatingFilterProxy delegatingFilterProxy = new DelegatingFilterProxy();
        delegatingFilterProxy.setTargetFilterLifecycle(true);
        delegatingFilterProxy.setTargetBeanName("shiroFilter");
        registrationBean.setFilter(delegatingFilterProxy);
        List urls = new ArrayList();
        urls.add("/*");   //给所有请求加过滤器
        //设置 有效url
        registrationBean.setUrlPatterns(urls);
        registrationBean.setOrder(2);

        return registrationBean;
    }
}
